<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>查询全部服务报告列表</title>
		<!-- css代码 start -->
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../css/checkbox.css" rel="stylesheet" />
		<link href="../../../../css/style.css" rel="stylesheet" />
		<link href="../../../../css/task.css" rel="stylesheet" />
		<style>
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.select-tzstate{
				width: 100%;
				border: 0;
				color: #a9a9a9;
				font-size: 16px;
				text-align: left;
				padding: 15px;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
			.details_con .btm .selectBtn {
			    line-height: 28px;
			    color: #ffffff;
			    background: #ea1e1a;
			}
			
			.item_box .item .text{
				margin: 5px auto;
			}
			.item_box .item .text span.cen{
				margin-left:0;
			}
			.item_box .item .text span{
				width: auto;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">查询全部服务报告列表</h1>
		</header>
		<div class="mui-content">
			
			<!-- <div class="details_con shadow">
				<div class="clum">
					<span class="name">仪器序列号</span>
					<span class="txt" id="serialNo">请输入仪器序列号</span>
				</div>
				<div class="clum">
					<span class="name">客户名称</span>
					<span class="txt" id="CustomerName">请输入客户名称</span>
				</div>
				<div class="clum">
					<span class="name">Div</span>
					<span class="txt" id="Div">请输入Div</span>
				</div>
				<div class="clum">
					<span class="name">BU</span>
					<span class="txt" id="bu">请输入BU</span>
				</div>
				<div class="clum">
					<span class="name">工作开始时间<em class="t_red">*</em></span>
					<button id='star' onclick="getDate('star')" type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum">
					<span class="name">工作结束时间<em class="t_red">*</em></span>
					<button id='end' onclick="getDate('end')" type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="btm autoHeight">
					注：查询近三个月的报告数据
					<p class="selectBtn"><span>查询</span></p>
				</div>
			</div> -->
			
			<div class="details_con select_con" id="search">
				<div class="clum">
					<input type="text" class="d_int_tp" id="serialNo" placeholder="输入仪器序列号" />
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="customerName" placeholder="输入客户名称" />
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="Div" placeholder="输入Div" />
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="bu" placeholder="输入BU" />
				</div>
				<div class="clum">
					<input id='star' type="text" class="d_int_tp" readonly="readonly" placeholder="请选择工作开始时间" style="background: #ea1e1a;border: 0">
				</div>
				<div class="clum">
					<input id='end' type="text" class="d_int_tp" readonly="readonly" placeholder="请选择工作结束时间" style="background: #ea1e1a;border: 0">
				</div>
					<span style="margin: 0 20px;color: #ddd;">注：查询近三个月的报告数据</span>
				<div class="btm autoHeight">
					<p class="selectBtn" id="searchBtn" onclick="getFWList()">查 询</p>
				</div>
			</div>
			<div class="details_con" style="margin: 30px 0 0 0;">
				<div class="item_box" id="liebiao">
					<!-- <div class="item">
						<div class="bar">
							<span class="number">1170001<img src="../../../../images/icon_58.png" /></span>
						</div>
						<div class="text">
							上海浦东医院
							<span>客户名称：</span>
						</div>
						<div class="type">
							<p>仪器型号：<span>Aloka Ssd 400</span><img src="../../../../images/icon_56.png"/></p>
							<p>DEVI-BU：<span>是</span><img src="../../images/icon_57.png"/></p>
						</div>
					</div>
					<div class="item">
						<div class="bar">
							<span class="number">1170001<img src="../../../../images/icon_58.png" /></span>
						</div>
						<div class="text">
							上海浦东医院
							<span>客户名称：</span>
						</div>
						<div class="type">
							<p>仪器型号：<span>Aloka Ssd 400</span><img src="../../../../images/icon_56.png"/></p>
							<p>DEVI-BU：<span>是</span><img src="../../../../images/icon_57.png"/></p>
						</div>
					</div> -->
				</div>
			</div>
		</div>
		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../../js/utils/rolldate.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			(function($, doc) {
				$.init();

				$.plusReady(function() {
					
					new Rolldate({
						el: '#star',
						format: 'YYYY-MM-DD',
						beginYear: 2015,
						endYear: 2050,
						trigger: 'click',
						lang: {
							title: '请选择工作开始时间',
						},
						confirm: function(date) {
							// jisuan(date)
						},
						cancel: function() {
						   h('#star').val("");
						}
					})
					
					new Rolldate({
						el: '#end',
						format: 'YYYY-MM-DD',
						beginYear: 2015,
						endYear: 2050,
						trigger: 'click',
						lang: {
							title: '请选择工作结束时间',
						},
						confirm: function(date) {
							// jisuan(date)
						},
						cancel: function() {
						   h('#end').val("");
						}
					})

					var lastWeekDate= getLastWeek()
					h('#star').val(lastWeekDate[0])
					h('#end').val(lastWeekDate[1])
					// getFWList()
				});
			}(mui, document));
			// 获取服务通知类别
			function getFWList(){
				var customerName = h('#customerName').val();
				var serialNo = h('#serialNo').val();
				var Div = h('#Div').val();
				var bu = h('#bu').val();
				
				var star = h('#star').val();
				var end = h('#end').val();
				if (star == "" || end == "" || star.indexOf("请选择") >= 0 || end.indexOf("请选择") >= 0) {
					app.toast("请选择时间");
					return false;
				}
				
				// 验证时间
				var checkreturn = checkTime();
				if (checkreturn) {
					app.toast(checkreturn);
					return false;
				}
				
				if(customerName=='' && serialNo=='' && Div=='' && bu==''){
					app.closeWaiting()
					app.toast("请输入搜索条件");
					return
				}
				
				app.showWaiting('加载中...')
				ajaxGet(BASE_URL + "cc/instrument/getInstrumentList", {
					CustomerName: customerName,
					serialNo: serialNo,
					Div: Div,
					bu: bu,
					starttime: star,
					endtime: end
				}, function(data) {
					app.closeWaiting()
					console.log(JSON.stringify(data))
					
					var html = "";
					h("#liebiao").html(html);
					if (data.code == 200) {
						if(data.data.code!=200){
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
							return
						}
						if(data.data.data!=""){
							for(var i=0;i<data.data.data.length;i++){
								var dts = data.data.data[i];
								var Instrument_id = dts.Instrument_id;
								var serial_no = dts.serial_no;
								var Instrument_no = dts.Instrument_no;
								var customer = dts.customer;
								var address = dts.address;
								html += '<div class="item" onclick="jumpToNext(\''+ Instrument_id +'\', \''+ serial_no +'\', \''+ customer +'\')">'
								html += '<div class="bar">'
								html += '<span class="number">'+serial_no+'<img src="../../../../images/icon_204.png" /></span>'
								html += '</div>'
								html += '<div class="type">'
								html += '<p><img src="../../../../images/icon_201.png"/>客户名称：<span>'+customer+'</span></p>'
								html += '<p><img src="../../../../images/icon_203.png"/>仪器型号：<span>'+Instrument_no+'</span></p>'
								// html += '<p>DEVI-BU：<span>是</span><img src="../../../../images/icon_57.png"/></p>'
								html += '</div>'
								html += '</div>';
							}
							h("#liebiao").html(html);
						}else{
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#liebiao").html(html);
						}
					} else {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#liebiao").html(html);
						app.toast(data.msg)
					}
					
				}, function(errorMsg) {
					app.closeWaiting()
					var html = '<div class="nodata">—— 暂无数据 ——</div>';
					h("#liebiao").html(html);
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			
			function jumpToNext(Instrument_id, serial_no, customer) {
				var star = h('#star').val();
				var end = h('#end').val();
				if (star == "" || end == "" || star.indexOf("请选择") >= 0 || end.indexOf("请选择") >= 0) {
					app.toast("请选择时间");
					return false;
				}
				// 验证时间
				var checkreturn = checkTime();
				if (checkreturn) {
					app.toast(checkreturn);
					return false;
				}
				app.jumpTo("/view/service/report/work/serviceReportList.html", "view/service/report/work/serviceReportList", {
					Instrument_id: Instrument_id,
					serial_no: serial_no,
					customer: customer,
					starttime: h("#star").val(),
					endtime: h("#end").val()
				});
			}
			
			function checkTime(){
				var begintime = h('#star').val();
				var endtime = h('#end').val();
				
				var time1 = new Date(begintime).getTime();
				var time2 = new Date(endtime).getTime();
				
				if(time1 > time2){
					return "开始时间不能大于结束时间";
				}
		
				//判断时间跨度是否大于3个月
				var arr1 = begintime.split('-');
				var arr2 = endtime.split('-');
				arr1[1] = parseInt(arr1[1]);
				arr1[2] = parseInt(arr1[2]);
				arr2[1] = parseInt(arr2[1]);
				arr2[2] = parseInt(arr2[2]);
				var flag = true;
				if(arr1[0] == arr2[0]){//同年
					if(arr2[1]-arr1[1] > 3){ //月间隔超过3个月
						flag = false;
					}else if(arr2[1]-arr1[1] == 3){ //月相隔3个月，比较日
						if(arr2[2] > arr1[2]){ //结束日期的日大于开始日期的日
							flag = false;
						}
					}
				}else{ //不同年
					if(arr2[0] - arr1[0] > 1){
						flag = false;
					}else if(arr2[0] - arr1[0] == 1){
						if(arr1[1] < 10){ //开始年的月份小于10时，不需要跨年
							flag = false;
						}else if(arr1[1]+3-arr2[1] < 12){ //月相隔大于3个月
							flag = false;
						}else if(arr1[1]+3-arr2[1] == 12){ //月相隔3个月，比较日
							if(arr2[2] > arr1[2]){ //结束日期的日大于开始日期的日
								flag = false;
							}
						}
					}
				}
				if(!flag){
					return "时间跨度不得超过3个月！";
				} else {
					return "";
				}
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
